package com.fan.shop.mock;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import com.fan.shop.domain.TransactionReference;
import com.fan.shop.domain.TransactionReferenceGroup;
import com.fan.shop.hibernate.utils.HibernateUtil;

public class TransactionReferenceGroupMock {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		TransactionReferenceGroupMock mock = new TransactionReferenceGroupMock();
		mock.insertGroups();
	}

	
	public void insertGroups()
	{
		SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
		Session session = sessionFactory.openSession();
		Transaction transaction = session.beginTransaction();
		
		TransactionReferenceGroup itemGroup = new TransactionReferenceGroup();
		itemGroup.setName("item");
		itemGroup.setDescription("item code generation");
		session.save(itemGroup);
		
		TransactionReferenceGroup poGroup = new TransactionReferenceGroup();
		poGroup.setName("pord");
		poGroup.setDescription("purchase order code generation");
		session.save(poGroup);
		
		TransactionReferenceGroup stockReqGroup = new TransactionReferenceGroup();
		stockReqGroup.setName("streq");
		stockReqGroup.setDescription("stock req code generation");
		session.save(stockReqGroup);
		
		
		TransactionReference item1 = new TransactionReference();
		item1.setName("item1");
		item1.setDescription("item1 code generation");
		item1.setPrefix("ITEM1_");
		item1.setStart(1);
		item1.setLast(1);
		item1.setMax(9999);
		item1.setGroupCode(itemGroup.getName());
		session.save(item1);
		
		
		TransactionReference item2 = new TransactionReference();
		item2.setName("item2");
		item2.setDescription("item2 code generation");
		item2.setPrefix("ITEM2_");
		item2.setStart(1);
		item2.setLast(1);
		item2.setMax(9999);
		item2.setGroupCode(itemGroup.getName());
		session.save(item2);
		
		
		
		transaction.commit();
		session.close();
	}
	
}
